package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.GreTreeCuringTechnologyDao;
import cn.topevery.garden.entity.po.GreTreeCuringTechnology;
import cn.topevery.garden.entity.query.GreTreeCuringTechnologyQuery;
import cn.topevery.garden.entity.vo.GreTreeCuringTechnologyVO;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import hw.topevery.framework.entity.KeyValue;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 古树名木养护技术表
 *
 * @author code-generate
 * @date 2022-02-27
 */
@Repository
public class GreTreeCuringTechnologyDaoImpl extends BaseDaoImpl<GreTreeCuringTechnology> implements GreTreeCuringTechnologyDao {
    @Override
    public <P extends DbCsp> List<GreTreeCuringTechnology> getSearch(P para) {
        return null;
    }

    

    @Override
    public DataPager<GreTreeCuringTechnologyVO> listPage(GreTreeCuringTechnologyQuery query) {
        String table = "t_gre_tree_curing_technology tgtct";

        String columns = "tgtct.*";

        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tgtct.c_id desc");
        sqlQueryMate
                .where(true, "tgtct.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(StringUtils.isNotBlank(query.getName()), "tgtct.c_name", ScriptConditionEnum.Like, query.getName())
                .where(query.getCheckResult()!=null, "tgtct.c_check_result", ScriptConditionEnum.Eq, query.getCheckResult())
                .where(StringUtils.isNotBlank(query.beginDate), "tgtct.c_db_create_date", ScriptConditionEnum.GreaterThanEq, query.beginDate)
                .where(StringUtils.isNotBlank(query.endDate), "tgtct.c_db_create_date", ScriptConditionEnum.LessThanEq, query.endDate)
        ;

        return getDataPager(sqlQueryMate, pageSize, pageIndex, GreTreeCuringTechnologyVO.class);
    }

    @Override
    public GreTreeCuringTechnology getEntityByColumn(String key,String value){
        KeyValue<String> map=new KeyValue<>();
        map.key=key;
        map.value=value;
        return getEntityByColumnEqValue(map);
    }
}
